#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>


struct stu {
	char name[20];
	int age;
};


void print(int arr[], int num)
{
	int i = 0;
	for (i = 0; i < num; i++)
	{
		printf("%d ", arr[i]);
	}
}

int int_cmp(const void* e1, const void* e2)
{
	return (*(int*)e1 - *(int* )e2);
}

int struct_stu_cmp_name(const void* e1, const void* e2)
{
	return strcmp(((struct stu*)e1)->name, ((struct stu*)e2)->name);
}

int struct_stu_cmp_age(const void* e1, const void* e2)
{
	return (((struct stu*)e1)->age - ((struct stu*)e2)->age);
}


int double_cmp(const void* e1, const void* e2)
{
	return (*(double*)e1 - *(double*)e2);
}



void test1()
{
	int arr[] = { 4,6,1,3,2,5,8,7,9,0 };
	int num = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, num, sizeof(arr[0]),int_cmp);
	print(arr, num);
}


void test2()
{
	struct stu arr[] = { {"zhangsan",31},{"lisi",23},{"wangwu",56} };
	int num = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, num, sizeof(arr[0]), struct_stu_cmp_name);

}

void test3()
{
	struct stu arr[] = { {"zhangsan",31},{"lisi",23},{"wangwu",56} };
	int num = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, num, sizeof(arr[0]), struct_stu_cmp_age);

}

void test4()
{
	double arr[] = { 1.1,5.5,2.2,3.3,4.4 };
	int num = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, num, sizeof(arr[0]), double_cmp);
	int i = 0;
	for (i = 0; i < num; i++)
	{
		printf("%lf ", arr[i]);
	}
}


int main()
{
	//test1();
	//test2();
	//test3();
	test4();
	return 0;
}